'use strict';

const Controller = require('egg').Controller;

class UserController extends Controller {
   // 创建
   async create() {
      const {
         ctx,
      } = this;
      console.log(JSON.stringify(ctx.request.body));
      ctx.body = await ctx.service.user.create(ctx.request.body);
   }

   // 删除
   async destroy() {
      const {
         ctx,
      } = this;
      const id = +ctx.params.id;
      ctx.body = await ctx.service.user.del(id);
   }

   // 更新
   async update() {
      const {
         ctx,
      } = this;
      const id = +ctx.params.id;
      const user = ctx.request.body;
      ctx.body = await ctx.service.user.update({
         id,
         user,
      });
   }

   // 登录
   async login() {
      const {
         ctx,
      } = this;
      const {
         name,
         password,
      } = ctx.request.body;
      ctx.body = await ctx.service.user.login({
         name,
         password,
      });
   }

   // 查找
   async find() {
      const {
         ctx,
      } = this;
      const id = +ctx.params.id;
      ctx.body = await ctx.service.user.find(id);
   }
}

module.exports = UserController;
``
